package cn.com.wdjedu.androidapp.wjeduandroid.ui.mainfragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;

import java.util.List;

import cn.com.wdjedu.androidapp.wjeduandroid.Login;
import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.Constanct;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.view.SpaceItemDecoration;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.introduceui.CourseIntroduceActivity;
import cn.com.wdjedu.androidapp.wjeduandroid.ui.videoshow.VideoShowActivity;

import static cn.com.wdjedu.androidapp.wjeduandroid.support.lib.utils.CommonUtils.getResources;

/**
 * Created by CCY on 2017/2/15.
 */



public class VideoItemAdapter extends CommonAdapter<MainBean.CourseBean> {


    public VideoItemAdapter(Context context, int layoutId, List<MainBean.CourseBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder viewHolder, final MainBean.CourseBean item, int position) {
     // viewHolder.setText(R.id.tv_name,"名师推荐666666666666666666666666666666666666666666666666666666666");
        viewHolder.setOnClickListener(R.id.tv_more, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("CourseType",2);
                bundle.putString("CourseName","Java");
                Intent intent = new Intent(mContext, CourseIntroduceActivity.class);
                intent.putExtras(bundle);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                mContext.startActivity(intent);
            }
        });
        RecyclerView recyclerView=viewHolder.getView(R.id.recyclerview);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        // 设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //设置间距
        int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacingInPixels);
        recyclerView.addItemDecoration(new SpaceItemDecoration(spacingInPixels));
        //去掉RecyclerView滑到边界产生的蓝色阴影
        recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
        VideoItemSubRVAdapter adapter=new VideoItemSubRVAdapter(mContext,R.layout.activity_index_gallery_item,item.getContent());
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
//          mContext  ----->  GlobalContext.getInstance().getApplicationContext()
                if( Constanct.USER_TOKEN != "") {
                    Intent intent = new Intent(mContext, VideoShowActivity.class);
                    Constanct.PLAYING_URL = item.getContent().get(position).getVideo_path();
                    Constanct.PLAYING_NAME = item.getContent().get(position).getName();
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                    Bundle bundle = new Bundle();
                    bundle.putInt("id", item.getContent().get(position).getId());//传递播放视频的ID，用于初始化章节显示
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                    // Toast.makeText(mContext,"播放id ："+item.getContent().get(position).getId(),Toast.LENGTH_LONG).show();
                }else{
                    Intent intent2 = new Intent(mContext, Login.class);
                    intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                    Toast.makeText(mContext,"观看免费视频之前请先登录(⊙o⊙)哦",Toast.LENGTH_LONG).show();
                    mContext.startActivity(intent2);
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }


}
